/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - geometry
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AEVertexDescriptor.inl
// Author:		Gianluca Belardelli
// Date:		09/02/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEVERTEXDESCRIPTOR_INL_
#define _AEVERTEXDESCRIPTOR_INL_

AE_FORCEINLINE AEVertexDescriptor::AEVertexDescriptor( void )
{
	Reset();
}

AE_FORCEINLINE void AEVertexDescriptor::Reset( void )
{
	m_sStride=0;
	m_sPosOfs = m_sColorOfs = m_sNormalOfs = m_sSecondaryColorOfs = -1;

	for( AEINT32 i=0; i < AEMAX_MESHBUFFER_TEXCOORDS; i++ )
		m_sTexCoordOfs[i]=-1;

	m_uiHash=0;
	m_byLastTexCoord = 0;
	m_byFirstTexCoord = 255;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::HasPosition( void ) const
{
	return m_sPosOfs != -1;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::HasColor( void ) const
{
	return m_sColorOfs != -1;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::HasSecondaryColor( void ) const
{
	return m_sSecondaryColorOfs != -1;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::HasNormal( void ) const
{
	return m_sNormalOfs != -1;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::HasTexCoord( AEINT32 nChannel ) const
{
	AEASSERT( nChannel >= 0 && nChannel < AEMAX_MESHBUFFER_TEXCOORDS );
	return m_sTexCoordOfs[ nChannel ] != -1;
}

AE_FORCEINLINE AEUINT32 AEVertexDescriptor::GetComponentFormat( AEINT32 nValue )
{
	return nValue & AEVERTEXDESC_FORMAT_MASK;
}

AE_FORCEINLINE const char *AEVertexDescriptor::GetComponentFormatString( AEINT32 nFormat )
{
	switch( nFormat )
	{
		case AEVERTEXDESC_FORMAT_FLOAT:return "float";
		case AEVERTEXDESC_FORMAT_FLOAT2:return "float2";
		case AEVERTEXDESC_FORMAT_FLOAT3:return "float3";
		case AEVERTEXDESC_FORMAT_FLOAT4:return "float4";
		case AEVERTEXDESC_FORMAT_BYTE4N:return "byte4N";
		case AEVERTEXDESC_FORMAT_SHORT2N:return "short2N";
		case AEVERTEXDESC_FORMAT_SHORT4N:return "short4N";
		case AEVERTEXDESC_FORMAT_HALF2:return "half2";
		case AEVERTEXDESC_FORMAT_HALF4:return "half4";
		case AEVERTEXDESC_FORMAT_USHORT2N:return "ushort2N";
		case AEVERTEXDESC_FORMAT_USHORT4N:return "ushort4N";
		case AEVERTEXDESC_FORMAT_BYTE4:return "byte4";
		case AEVERTEXDESC_FORMAT_SHORT2:return "short2";
		case AEVERTEXDESC_FORMAT_SHORT4:return "short4";
		//case VERTEXDESC_FORMAT_UBYTE4N:return "ubyte4N";
	}
	return "unknown";
}

AE_FORCEINLINE AEINT32 AEVertexDescriptor::GetComponentOffset( AEINT32 nValue )
{
	return nValue & AEVERTEXDESC_OFFSET_MASK;
}

AE_FORCEINLINE AEUINT32 AEVertexDescriptor::GetHash( void ) const
{
	return m_uiHash;
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::operator == ( const AEVertexDescriptor& other ) const
{
	return Equals( other );
}

AE_FORCEINLINE AEBOOL32 AEVertexDescriptor::operator != ( const AEVertexDescriptor& other ) const
{
	return !Equals( other );
}

#endif // _AEVERTEXDESCRIPTOR_INL_
